public class MyQueue {
    //双向链表队列
    static class ListNode{
        public int val;
        public ListNode prev;
        public ListNode next;
        public ListNode(int val){
            this.val=val;
        }
    }
    //尾入头删
    public ListNode first=null;
    public ListNode last=null;
    public int usedSize=0;
    public void offer(int val){
        ListNode cur=new ListNode(val);
        if(isEmpty()){
            first= last=cur;
            usedSize++;
        }else {
            last.next=cur;
            cur.prev=last;
            last=cur;
        }
        usedSize++;
    }
    public int poll(){
        int popElement=first.val;
        if(isEmpty()){
            return -1;
        }
        first=first.next;
        if(first!=null){
            first.prev=null;
        }
        usedSize--;
        return popElement;
    }

    public int peek(){
        if(isEmpty()){
            return -1;
        }else {
            return first.val;
        }
    }
    public boolean isEmpty(){
        return usedSize==0;
    }
}
